package com.sea.supply.service.impl;


import com.codecrane.core.Constants;
import com.codecrane.core.power.entity.PowerUser;
import com.sea.supply.entity.Buy;
import com.sea.supply.entity.ProduceDetail;
import com.sea.supply.entity.ProduceRecord;
import com.sea.supply.mapper.ProduceDetailMapper;
import com.sea.supply.mapper.ProduceRecordMapper;
import com.sea.supply.service.BuyService;
import com.sea.supply.service.ProduceDetailService;
import com.sea.supply.service.ProduceRecordService;
import com.sea.supply.service.ProduceService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 陈鸿飞
 */
@Service
public class ProduceRecordServiceImpl implements ProduceRecordService {

    @Autowired
    private ProduceRecordMapper produceRecordMapper;


    @Override
    public int save(ProduceRecord produceRecord) {
        return produceRecordMapper.insert(produceRecord);
    }

    @Override
    public int save(Integer produceId, Integer produceStatus, String produceRemark) {
        PowerUser user = (PowerUser) SecurityUtils.getSubject().getSession().getAttribute(Constants.CURRENT_USER_SESSION);
        ProduceRecord produceRecord=new ProduceRecord();
        produceRecord.setProduceId(produceId);
        produceRecord.setProduceStatus(produceStatus);
        produceRecord.setProduceRemark(produceRemark);
        produceRecord.setProduceMember(user.getUserRealname());
        return produceRecordMapper.insert(produceRecord);
    }

    @Override
    public List<ProduceRecord> findByProduceId(Integer produceId) {
        return produceRecordMapper.findByProduceId(produceId);
    }


}
